(function(root) {

  root.localStream = null;
  
  requestCameraAccess = root.requestCameraAccess = function() {
    console.log('Requested access to camera');
    
    getUserMedia({
      'audio' : true, 
      'video' : { mandatory: { maxWidth: 480 } }
    }, onCameraAccessGranted);
  }
  
  function onCameraAccessGranted(stream) {
    console.log('Access to camera granted');
    
    document.querySelector('#localVideo').src = URL.createObjectURL(stream);
    root.localStream = stream;
    
    if (isCaller === true) {
      root.createPeerConnection();
    }
  }
  
  window.onbeforeunload = function() {
      root.localSteam.close();
  }
})(this);
